In [1]:
data = [1, 2, 3, 4, 5, 6, 8]
In [2]:
def find_missing_number(data):
ans = ((len(data) + 1) * (len(data) + 2)) / 2
for x in data:
ans -= x
return ans
In [3]:
print find_missing_number(data)
In [4]:
def find_missing_number_xor(data):
a = data[0]
for x in data[1:]:
a ^= x
b = 1
for i in xrange(2, len(data) + 2):
b ^= i
return a ^ b
In [5]:
print find_missing_number_xor(data)